{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from datetime import date\n",
    "from gs_quant.common import PayReceive, Currency\n",
    "from gs_quant.instrument import IRSwap\n",
    "from gs_quant.markets import HistoricalPricingContext\n",
    "from gs_quant.session import Environment, GsSession"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# external users should substitute their client id and secret; please skip this step if using internal jupyterhub\n",
    "GsSession.use(Environment.PROD, client_id=None, client_secret=None, scopes=('run_analytics',))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# create 2 swaps and fix swap_b parameters by resolving. Swap_a parameters will resolve in HistoricalPricingContext\n",
    "swap_a = IRSwap(PayReceive.Pay, '30y', Currency.USD, fixed_rate='atm+5')\n",
    "swap_b = IRSwap(PayReceive.Pay, '30y', Currency.USD, fixed_rate='atm+5')\n",
    "swap_b.resolve()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "with HistoricalPricingContext(date(2019,1,15), date.today()):\n",
    "    res_a_f = swap_a.price()\n",
    "    res_b_f = swap_b.price()  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "res_a = res_a_f.result()\n",
    "res_b = res_b_f.result()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "\n",
    "plt.plot(res_a, 'g-', label='Rolling 30y GBP Payer struck atm+5bps')\n",
    "plt.plot(res_b, 'b-', label='30y GBP Payer struck atm+5bps over time')\n",
    "plt.xlabel('time')\n",
    "plt.ylabel('PV ($)')\n",
    "plt.title('PV over Time')\n",
    "plt.legend()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "pycharm": {
   "stem_cell": {
    "cell_type": "raw",
    "metadata": {
     "collapsed": false
    },
    "source": []
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
